export default {
  data() {
    return {
      idLabel: 'id',
      deleteTip: '此操作将永久删除该记录, 是否继续?',
      dataLoading: false,
      listData: [],
      multipleSelection: [], //多选结果
      totalSize: 0, //列表记录总数
      pagination: {
        pageNum: 1,
        pageSize: 10,
      },
    }
  },
  created() {
    // this.getList()
  },
  methods: {
    /**
     * 详情
     */
    handleShowDetail(row) {
      if (this.$refs.hasOwnProperty('itemDetail')) {
        this.$refs.itemDetail.show('detail', row);
      }
    },
    /**
     * 添加按钮
     */
    handleItemAdd() {
      if (this.$refs.hasOwnProperty('itemDetail')) {
        this.$refs.itemDetail.show('add');
      }
    },
    /**
     * 编辑行记录
     * @param row
     */
    handleEditItem(row) {
      if (this.$refs.hasOwnProperty('itemDetail')) {
        this.$refs.itemDetail.show('edit', row);
      }
    },

    /**
     * 删除行记录
     * @param row
     */
    handleDeleteItem(row) {
      this.$confirm(this.deleteTip, '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        cancelButtonClass: 'cancel-msgbtn', confirmButtonClass: 'confirm-msgbtn', type: 'warning',
      }).then(() => {
        this.batchDelete(row[this.idLabel]).then(res => {
          this.$message.success('删除成功');
          this.getList()
        })
      }).catch(() => { });
    },

    /**
     * 获取更新表格数据
     * @param params 筛选条件
     * @param reset 是否重置筛选条件
     */
    getList(params, reset) {
      if (reset) {
        this.filterParams = params;
      } else {
        Object.assign(this.filterParams, params)
      }
      this.dataLoading = true;
      this.listData = [];
      if (this.filterParamsHandle) {
        this.filterParamsHandle();
      }
      this.list(this.filterParams).then(res => {
        if (this.rowDataHandle) {
          this.rowDataHandle(res.rows)
        } else {
          this.listData = res.rows;
        }
        this.totalSize = res.total;
        this.dataLoading = false;
      }).catch(() => {
        this.dataLoading = false
      })
    },

  }
}
